#include<iostream>
using namespace std;
int n;
int main()
{
	int ma = -1000;
	int mi = 10000;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (a < mi) {
			mi = a;
		}
		if (a > ma) {
			ma = a;
		}
	}
	cout << (n - 1) * (ma - mi) << endl;
	return 0;
}